package com.lzjy.tw.composedemo.di

import android.content.Context
import androidx.room.Room
import com.lzjy.tw.composedemo.domain.TestRoomData
import com.lzjy.tw.composedemo.domain.dao.TestDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object RoomModule {

    @Singleton
    @Provides
    fun provideDatabase(@ApplicationContext app: Context): TestRoomData {
        return Room.databaseBuilder(
            app,
            TestRoomData::class.java,
            "test.db"
        ).build()
    }
    @Singleton
    @Provides
    fun provideTestDao(database: TestRoomData): TestDao {
        return database.testDao()
    }
}